package com.panopset.gui.container;

import static com.panopset.Util.*;

/**
 *
 * @author Karl Dinwiddie
 */
public class PanLongField extends PanNumericOnlyField {
    private static final String LONG_FIELD_MESSAGE = x("Please enter a long value, no decimal places.");

    public Long getLongValue() {
        return Long.parseLong(getValue());
    }

    public PanLongField(int cols, String borderTitle, String toolTipText,
            String defaultValue) {
        super(cols, borderTitle, toolTipText, defaultValue);
        addValidator(new Validator() {

            @Override
            public String validate(String value) {
                if (value == null) {
                    return LONG_FIELD_MESSAGE;
                }
                try {
                    Long.parseLong(value);
                } catch(NumberFormatException ex) {
                    return LONG_FIELD_MESSAGE;
                }
                return null;
            }
        });
    }

}
